<template>
    <div ref="topDiv">
        <Split v-model="split1" style="height: 100%; " class="demo-split">
            <div slot="left" style="height: 100%; overflow-y: auto; overflow-x: hidden; padding: 5px">
                <Tree ref="tree" :data="apsgTree" :load-data="handleLoadData" :render="renderContent" style="width: 100%"></Tree>
                <Dropdown trigger="click" style="margin-left:20px" placement="right-start"
                          ref="contentMenu" @on-click="selectMenuItem">
                    <DropdownMenu slot="list">
                        <DropdownItem name="addApsgItemType">添加条目</dropdownitem>
                        <DropdownItem name="editApsgItemType">修改条目</dropdownitem>
                        <DropdownItem name="relatedOrg">关联组织机构</dropdownitem>
                        <DropdownItem name="deleteApsgItemType">删除条目</dropdownitem>
                    </dropdownmenu>
                </dropdown>
            </div>
            <div slot="right" class="demo-split-pane">
                <Form :label-width="100" ref="formInline" :model="formInline">
                    <Row :gutter="16" class="query-form">
                        <i-col span="8">
                            <FormItem label="隐患编号：" prop="name">
                                <Input v-model="formInline.name"  placeholder="请填写隐患编号"/>
                            </FormItem>
                        </i-col>
                        <i-col span="8">
                            <FormItem label="排查内容：" prop="remark">
                                <Input v-model="formInline.remark" placeholder="请填写排查内容"/>
                            </FormItem>
                        </i-col>
                        <i-col span="8">
                            <div style="float: right">
                                <Button class="ivu-btn-reset" style="margin-left: 10px" @click="cancel">重置</Button>
                                <Button class="ivu-btn-query" icon="md-search"  @click="query">查询</Button>
                            </div>
                        </i-col>
                    </Row>
                    <Row class="query-form">
                        <Col span="24">
                            <Button size="large" type="success" class="ivu-btn-add" icon="md-add"
                                    @click="addApsgItemTypeContent">新增
                            </Button>
                        </Col>
                    </Row>
                </Form>
                <Table ref='table' :loading="loading" border :columns="columns" no-data-text="请选择隐患条目分类"
                        :data="infos" width="100%" :height="tableHeight2"  highlight-row stripe size="small"></Table>
                <Row type="flex" justify="end" >
                    <i-col>
                        <Page :total="pagedata.total" :current="pagedata.currentPage" :page-size="pagedata.pageSize"
                                @on-page-size-change="pageSizeChange" @on-change="pageChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
                    </i-col>
                </Row>
            </div>
        </Split>
        <Modal :title="modalTitle" :transfer=false :mask-closable="false" v-model="apsgItemTypeView" :width=600>
            <Form :model="formItem"   ref="formCustom"  label-position="top" :rules="ruleCustom">
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="上级分类：" prop="parentName">
                            <Input v-model="formItem.parentName" readonly></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="上级编码：" prop="parentCode">
                            <Input v-model="formItem.parentCode" readonly></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="编号：" prop="code">
                            <Input v-model="formItem.code" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="名称：" prop="name">
                            <Input v-model="formItem.name" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="分类类型：">
                            <Select v-model="formItem.type">
                                <Option value="1">专业</Option>
                                <Option value="2">排查类型</Option>
                                <Option value="3">排查项目</Option>
                                <Option value="4">排查项目2</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="11"></Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="对接类型大类：">
                            <Input v-model="formItem.itemType1" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="对接类型小类：">
                            <Input v-model="formItem.itemType2" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="描述：">
                            <Input type="textarea" v-model="formItem.desc" ></Input>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' :loading="buttonLoading" @click="saveOrUpdate('formCustom')">确定</Button>
                <Button type="primary" class='ivu-btn-cancel' @click="handleCancelApsgItem" style="margin-left: 2px">取消</Button>
            </div>
        </Modal>

        <Modal title="条目机构映射" :transfer=false v-model="relateOrgView" :width=1200 >
            <Split v-model="split2" style="height: 400px">
                <div slot="left" style="height: 100%; overflow-y: auto; overflow-x: hidden; padding: 5px">
                    <Table height="400"   :columns="columns2" :data="apsgTypeOrg" border></Table>
                </div>
                <div slot="right" style="margin-left:20px;height:100%;overflow-y:auto">
                    <Tree :data="orgTree" :load-data="loadData" @on-select-change="treechange" style="font-size: 29px;overflow-x:auto;overflow-y:auto"></Tree>
                </div>
            </Split>
        </Modal>

        <Modal :title="apsgItemTitle" :transfer=false v-model="apsgItemView" :width=600>
            <Form :model="apsgItemCustom"  ref="apsgItemCustom"  label-position="top" :rules="ruleCustom2">
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="排查项目：" prop="idApitemclassfyName">
                            <Input v-model="apsgItemCustom.idApitemclassfyName" readonly></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="隐患编号：" prop="idApitemclassfyCode">
                            <Input v-model="apsgItemCustom.idApitemclassfyCode" readonly></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="隐患等级：" prop="level">
                            <Select v-model="apsgItemCustom.level">
                                <Option value="Ⅰ">Ⅰ</Option>
                                <Option value="Ⅱ">Ⅱ</Option>
                                <Option value="Ⅲ">Ⅲ</Option>
                                <Option value="Ⅳ">Ⅳ</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="整改时限（天）：" prop="recPeriod">
                            <Input v-model="apsgItemCustom.recPeriod" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="扣分值（分）："  prop="score">
                             <Input v-model="apsgItemCustom.score" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="推送周期：" prop="periodPush">
                            <Input v-model="apsgItemCustom.periodPush" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="类型大类：">
                            <Input v-model="apsgItemCustom.itemType1" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="类型小类：">
                            <Input v-model="apsgItemCustom.itemType2" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="排查内容：" prop="content">
                            <Input type="textarea" v-model="apsgItemCustom.content" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="控制措施：" prop="control">
                            <Input type="textarea" v-model="apsgItemCustom.control" ></Input>
                        </FormItem>
                    </Col>
                </Row>
       <!--         <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="描述：" >
                            <Input type="textarea" v-model="apsgItemCustom.desc" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="参考依据：">
                            <Input type="textarea" v-model="formItem.desc" ></Input>
                        </FormItem>
                    </Col>
                </Row>  -->
            </Form>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' :loading="buttonLoading" @click="saveOrUpdateApsgItem('apsgItemCustom')">确定</Button>
                <Button type="primary" class='ivu-btn-cancel' @click="handleCancel" style="margin-left: 2px">取消</Button>
            </div>
        </Modal>

        <Modal title="条目内容查看" class="modal-view-detail"  :transfer=false v-model="apsgItemDataView" :width=600>
            <Form :model="apsgItemCustom" :label-width="160" >
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="排查项目：" prop="idApitemclassfyName">
                            {{apsgItemData.idApitemclassfyName}}
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="隐患编号：" prop="idApitemclassfyCode">
                            {{apsgItemData.idApitemclassfyCode}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="隐患等级：" prop="level">
                            {{apsgItemData.level}}
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="整改时限（天）：" prop="recPeriod">
                            {{apsgItemData.recPeriod}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="扣分值（分）："  prop="score">
                             {{apsgItemData.score}}
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="推送周期：" prop="periodPush">
                            {{apsgItemData.periodPush}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="类型大类：">
                            {{apsgItemData.itemType1}}
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="类型小类：">
                            {{apsgItemData.itemType2}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="排查内容：" prop="content">
                            {{apsgItemData.content}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="控制措施：" prop="control">
                            {{apsgItemData.control}}
                        </FormItem>
                    </Col>
                </Row>
       <!--         <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="描述：" >
                            {{apsgItemData.desc}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="24">
                        <FormItem label="参考依据：">
                            {{apsgItemData..desc}}
                        </FormItem>
                    </Col>
                </Row>  -->
            </Form>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="apsgItemDataView=false">关闭</Button>
            </div>
        </Modal>

        <Modal title="条目查看"  class="modal-view-detail"  :transfer=false v-model="apsgItemTypeDataView" :width=600>
            <Form :model="viewData" :label-width="120">
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="编号：" prop="code">
                            {{viewData.code}}
                        </formitem>
                    </Col>
                    <Col span="11">
                        <FormItem label="名称：" prop="name">
                            {{viewData.name}}
                        </formitem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label="上级分类：" prop="parentName">
                           {{viewData.parentName}}
                        </formitem>
                    </Col>
                    <Col span="11">
                        <FormItem label="分类类型：">
                            {{viewData.type=="1"?"专业":
                            (viewData.type=="2"?"排查类型":
                            (viewData.type=="3"?"排查项目":
                            (viewData.type=="4"?"排查项目2":"")))}}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="apsgItemTypeDataView=false">关闭</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
    import {sessionStorage} from '@/common/cacheUtils.js';
    import {Api} from '../../../api/index.js'
    export default{
        data () {
            return {
                selectNode: {},
                selectRoot: [],
                selectNodeInfo:{},
                selectNode:"",
                orgTree: [],
                apsgItemTitle: "",
                relateOrgView: false,
                apsgTypeOrg: [],
                apsgItemList: [],
                selectedApsgType: {},
                apsgItemData: {},
                tableHeight1: 300,
                tableHeight2: 300,
                loading3: false,
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                pageSizeArray: [10, 20, 50],
                loading: false,
                formItem: {},
                viewData: {},
                split1: 0.25,
                split2: 0.45,
                formInline: {},
                apsgItemCustom: {},
                apsgItemView: false,
                apsgItemTypeView: false,
                apsgItemDataView: false,
                apsgItemTypeDataView: false,
                modalTitle:"",
                buttonLoading: false,
                columns2:[
                    {
                        title: '组织机构名称',
                        key: 'orgName',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        maxWidth: 270,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: 'red'
                                    },
                                    on: {
                                        click: () => {
                                            this.toDeleteApsgOrg(params.row);
                                        }
                                    }
                                }, '删除'),
                            ]);
                        }
                    }
                ],
                ruleCustom: {
                    code: [{
                        required: true,
                        message: '  ',
                        trigger: 'blur'
                    }],
                    title: [{
                        required: true,
                        message: '  ',
                        trigger: 'blur'
                    }],
                    parentId: [{
                        required: true,
                        message: '  ',
                        trigger: 'blur'
                    }],
                    type: [{
                        required: true,
                        message: '  ',
                        trigger: 'blur'
                    }]
                },
                ruleCustom2: {
                    level: [{
                        required: true,
                        message: '  ',
                        trigger: 'blur'
                    }],
                    content: [{
                        required: true,
                        message: '  ',
                        trigger: 'blur'
                    }]
                },
                apsgTree: [{
                    id:'1',
                    code : '1',
                    title : '隐患条目分类',
                    type : '',
                    parentName : '',
                    children: [],
                    _loading: false,
                    _showChildren: true
                }],
                columns: [
                    {
                        type: 'index',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },
                    {
                        title: '隐患等级',
                        align: 'center',
                        key: 'level',
                        width: 100,
                        render:(h,params)=>{
                            return h('div',[
                                h('span',params.row.level || '--')
                            ]);
                        }
                    },
                    {
                        title: '发现隐患',
                        align: 'center',
                        key: 'apCount',
                        width: 100,
                        render:(h,params)=>{
                            return h('div',[
                                h('span',params.row.apCount || '--')
                            ]);
                        }
                    },
                    {
                        title: '排查内容',
                        align: 'center',
                        key: 'content',
                        render:(h,params)=>{
                            return h('div',[
                                h('span',params.row.content || '--')
                            ]);
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        maxWidth: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.code == "1" ? '#d0d0d0' : '',
                                        pointerEvents: params.row.code == "1" ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.toViewApsgItem(params.row);
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.code == "1" ? '#d0d0d0' : '',
                                        pointerEvents: params.row.code == "1" ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.toEditApsgItem(params.row);
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.code == "1" ? '#d0d0d0' : 'red',
                                        pointerEvents: params.row.code == "1" ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.toDeleteApsgItem(params.row);
                                        }
                                    }
                                }, '删除'),
                            ]);
                        }
                    }
                ],
                infos: [],
                view:true,
                isAdd:false,
            }
        },
        mounted() {
            this.$refs.topDiv.style.height = (window.innerHeight - 120) + 'px';
            this.tableHeight1 = window.innerHeight - 185
            this.tableHeight2 = window.innerHeight - 240
            this.getApsgItemByParentId(this.apsgTree[0]);
            this.getOrgInfoTree();
            this.selectedApsgType = this.apsgTree[0];
        },
        methods: {
            selectMenuItem(name){
                if(name == "addApsgItemType"){
                    this.toAddChildrenType(this.selectNodeInfo);
                }
                if(name == "editApsgItemType"){
                    this.toEdit(this.selectNodeInfo);
                }
                if(name == "relatedOrg"){
                    this.toRelateOrg(this.selectNodeInfo);
                }
                if(name == "deleteApsgItemType"){
                    this.$Modal.confirm({
                        title: '提示信息',
                        content: '<p>删除该菜单及其子菜单</p>',
                        okText:'确认',
                        cancelText:'取消',
                        onOk: () => {
                            this.$http.delete(Api.deleteApsgItem + "/"+this.selectNodeInfo.id, {params:{}
                            }).then(res=>{
                                const parentKey = this.selectRoot.find(el => el === this.selectNode).parent;
                                const parent = this.selectRoot.find(el => el.nodeKey === parentKey).node;
                                for(var i=0;i<parent.children.length;i++){
                                    if(parent.children[i].id == this.selectNodeInfo.id)
                                    {
                                        parent.children.splice(i, 1);
                                        this.$Message.success('删除成功');
                                        return ;
                                    }
                                }
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        }
                    })
                }
            },
            addApsgItemTypeContent(){
                this.apsgItemCustom = {idApitemclassfy:this.selectNodeInfo.id,
                    idApitemclassfyCode:this.selectNodeInfo.code,idApitemclassfyName:this.selectNodeInfo.title};
                this.apsgItemTitle = "条目内容新增"
                this.apsgItemView = true;
                this.isAdd = true;
            },
            loadData(item, callback) {
				item.loading3 = true;
				this.$http.get(Api.queryOrg, {
					params: {
                        parentId: item.orgId,
                        codeAffordIf : 0
					}
				}).then(res => {
                    item.loading3 = false;
					if(res.data.data.length !== 0) {
						res.data.data.map(i => {
							i.title = i.orgName
							delete i['orgName']
							i.loading = false;
							i.children = [];
						})
						item.children = res.data.data;
                        callback(item.children);
					} else {
						delete item['children'];
						delete item['loading'];
					}
				}).catch(e => {
				    console.log(e);
					this.$Message.error('请求失败');
				})
			},
            treechange(data, item) {
                var req = {};
                req.itemTypeId = this.selectedApsgType.id;
                req.orgId = item.orgId;
                req.orgName = item.title;
				this.$http.post(Api.saveApsgItemOrg,req).then(res => {
				    this.apsgTypeOrg.unshift(req);
				}).catch(e => {
					this.$Message.error('请求失败');
				})
			},
            handleLoadData (item, callback) {
                setTimeout(() => {
                    this.$http.get(Api.getApsgItemType, {params:{parentId:item.id}}).then(res => {
                        callback(res.data);
                    }).catch(e => {
                        this.$Message.error('请求失败');
                    })
                }, 2000);
            },
            apsgTableCellDbClick(row, index){
                this.query(row.id,row.type);
            },
            apsgTableCellClick(row,index){
            },
            getApsgItemByParentId(parent){
                let user = sessionStorage('userId').getObject('userId');
                this.$http.get(Api.getApsgItemType, {params:{parentId:parent.id,loginId:user.loginId,companyId:user.companyId}}).then(res => {
                    this.$set(parent,'children',res.data);
                    //this.$Message.success('成功');
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            pageSizeChange(pageSize){
                this.pagedata.pageSize = pageSize;
                this.query(this.selectNodeInfo.id,this.selectNodeInfo.type);
            },
            pageChange(pageNum){
                this.pagedata.currentPage = pageNum;
                this.query(this.selectNodeInfo.id,this.selectNodeInfo.type);
            },
            saveOrUpdate(name){
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.buttonLoading = true
                        if(this.isAdd){
                            this.formItem.id = this.uuid();
                            this.$http.post(Api.saveApsgType, this.formItem).then(res => {
                                this.buttonLoading = false
                                this.formItem.title = this.formItem.name;
                                this.formItem.loadng = false;
                                this.formItem._loadng = false;
                                this.selectRoot.find(el => {
                                    if(el === this.selectNode){
                                        el.node.expand = true;
                                        this.getApsgItemByParentId(el.node);
                                        this.$Message.success('成功');
                                        this.apsgItemTypeView = false;
                                    }
                                })
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        }else{
                            this.$http.put( Api.updateApsgType, this.formItem).then(res => {
                                this.buttonLoading = false
                                this.formItem.title = this.formItem.name;
                                this.selectedApsgType = Object.assign(this.selectedApsgType, JSON.parse(JSON.stringify(this.formItem)));
                                this.apsgItemTypeView = false;
                                this.$Message.success('成功');
                            }).catch(e => {
                                this.$Message.error('请求失败');
                             })
                        }
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            },
            saveOrUpdateApsgItem(name){
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.buttonLoading = true
                        if(this.isAdd){
                            this.apsgItemCustom.id = this.uuid();
                            this.$http.post(Api.saveApsgItem, this.apsgItemCustom).then(res => {
                                this.buttonLoading = false
                                this.apsgItemView = false;
                                this.query(this.selectNodeInfo.id,this.selectNodeInfo.type);
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        }else{
                            this.$http.put( Api.updateApsgItem, this.apsgItemCustom).then(res => {
                                this.buttonLoading = false
                                this.query(this.selectNodeInfo.id,this.selectNodeInfo.type);
                                this.apsgItemView = false;
                                this.$Message.success('成功');
                            }).catch(e => {
                                this.$Message.error('请求失败');
                             })
                        }
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            },
            getOrgInfoTree(){
                this.orgTree = [];
            	this.$http.get(Api.queryOrg, {
					params: {
                        parentId: -1,
                        codeAffordIf : 0
					}
				}).then(res => {
					res.data.data.map(i => {
						i.title = i.orgName;
						delete i['orgName'];
						i.loading = false;
						i.children = [];
					})
					this.orgTree.push(res.data.data[0]);
				}).catch(e => {
					this.$Message.error('请求失败');
				})
            },
            handleCancel() {
                this.apsgItemTypeView = false;
            },
            handleCancelApsgItem() {
                this.laoding = false;
                this.apsgItemTypeView = false;
            },
            toAddChildrenType(row){
                this.selectedApsgType = row;
            //    if(this.selectedApsgType == {}){
            //        this.$Message.error('请选择父条目');
            //    }
                this.modalTitle = "菜单新增"
                this.formItem = {parentId:this.selectedApsgType.id,parentName:this.selectedApsgType.title,parentCode:this.selectedApsgType.code};
                this.apsgItemTypeView = true;
                this.isAdd = true;
            },
            toEdit(row){
                this.$http.get(Api.apsgItemTypeById + "/" + row.id).then(res => {
                    this.selectedApsgType = row;
                    this.modalTitle = "条目修改"
                    this.formItem = res.data;
                    this.apsgItemTypeView = true;
                    this.isAdd = false;
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            toViewData(row){
                this.$http.get(Api.apsgItemTypeById + "/" + row.id).then(res => {
                     this.viewData  = res.data;
                     this.apsgItemTypeDataView = true;
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            toViewApsgItem(row){
                this.apsgItemData = row;
                this.apsgItemData.idApitemclassfy = this.selectNodeInfo.id;
                this.apsgItemData.idApitemclassfyCode = this.selectNodeInfo.code
                this.apsgItemData.idApitemclassfyName = this.selectNodeInfo.title;
                this.apsgItemDataView = true;
            },
            toEditApsgItem(row){
                this.apsgItemTitle = "条目内容编辑"
                this.apsgItemCustom = row;
                this.apsgItemCustom.idApitemclassfy = this.selectNodeInfo.id;
                this.apsgItemCustom.idApitemclassfyCode = this.selectNodeInfo.code
                this.apsgItemCustom.idApitemclassfyName = this.selectNodeInfo.title;
                this.apsgItemView = true;
                this.isAdd = false;
            },
            toDeleteApsgItem(row){
                    this.$http.delete(Api.deleteApsgItemById + "/" + row.id).then(res => {
                    if(res.data.status == 200){
                        this.infos.splice(row._index,1);
                        this.$Message.success('请求成功');
                    }
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            cancel(){
                this.formInline = {};

            },
            query(id,type){
                this.loading = true;
                let user = sessionStorage('userId').getObject('userId');
                let data = {
                    startPage: this.pagedata.currentPage,
                    pageSize: this.pagedata.pageSize,
                    idApitemclassfy: id,
                    aptype: type,
                    orgId: user.orgInfo.orgId
                };
                data = Object.assign(data,JSON.parse(JSON.stringify(this.formInline)));
                this.$http.get(Api.apsgItem, {params: data}).then(res => {
                    this.infos = res.data.data;
                    this.pagedata.total = res.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            toRelateOrg(row){
                this.selectedApsgType = row;
                this.$http.get(Api.getApsgItemTypeOrgByTypeId + "/" + row.id).then(res => {
                     this.apsgTypeOrg  = res.data.data;
                     this.relateOrgView = true;
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            toDeleteApsgOrg(row){
                this.$http.delete(Api.deleteApsgItemOrg + "/" + row.id).then(res => {
                    if(res.data.status == 200){
                        this.apsgTypeOrg.splice(row._index,1);
                        this.$Message.success('请求成功');
                    }
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            uuid() {
                var s = [];
                var hexDigits = "0123456789abcdef";
                for (var i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
                s[8] = s[13] = s[18] = s[23] = "-";

                var uuid = s.join("");
                return uuid;
            },
            renderContent (h, { root, node, data }) {
                let icon = "ios-folder";
                return h('span', {
                    style: {
                        display: 'inline-block',
                        cursor: "pointer",
                        color: node.node.selected ? "#2d8cf0" : "black" //根据选中状态设置样式
                    },
                    on:{
                        click: () => {
                            this.selectNodeInfo = data;
                            this.query(this.selectNodeInfo.id,this.selectNodeInfo.type);
                            if (!node.node.selected)  this.$refs.tree.handleSelect(node.nodeKey);
                        },
                        //右键点击事件
                        contextmenu: (e) => {
                            e.preventDefault();
                            this.selectNodeInfo = data;
                            this.selectRoot = root;
                            this.selectNode = node;
                            this.$refs.contentMenu.$refs.reference = event.target;
                            this.$refs.contentMenu.currentVisible = !this.$refs.contentMenu.currentVisible;
                        },
                    }
                },
                    [
                    h('span', [
                        h('Icon', {
                            props: {
                                type: icon,
                            },
                            style: {
                                marginRight: '5px',
                                color: '#FF7F00'
                            }
                        }),
                        h('span', data.title)
                    ])
                ]
                );
            },
        },
    }
</script>
<style>
     @import './../../../index.css';
 .demo-split{
        height: 200px;
        border: 1px solid #dcdee2;
    }
    .demo-split-pane{
        padding: 10px;
    }
      .test-5::-webkit-scrollbar {
  /*滚动条整体样式*/
  width : 10px;  /*高宽分别对应横竖滚动条的尺寸*/
  height: 1px;
  }
  .test-5::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius   : 10px;
  background-color: skyblue;
  background-image: -webkit-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.2) 25%,
      transparent 25%,
      transparent 50%,
      rgba(255, 255, 255, 0.2) 50%,
      rgba(255, 255, 255, 0.2) 75%,
      transparent 75%,
      transparent
  );
  }
  .test-5::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2);
  background   : #ededed;
  border-radius: 10px;
  }
</style>
